package com.ckerchina.admin.ckadmin.controller.console;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ckerchina.admin.ckadmin.dao.MgrUserAndMenuDAO;
import com.ckerchina.admin.ckadmin.domain.mgr.MgrUser;
import com.ckerchina.admin.ckadmin.exception.ErrorCode;
import com.ckerchina.admin.ckadmin.exception.ZhuziException;
import com.ckerchina.admin.ckadmin.service.mgr.MgrUserDetail;

/**
 * 后台管理功能抽象类
 */
@RequestMapping(value = "/console")
public abstract class AbstractConsoleController {

	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	private MgrUserAndMenuDAO mgrUserAndMenuDAO;

	/**
	 * 获取后台登录用户信息
	 */
	protected MgrUser getMgrUser() {
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if (authentication == null) {
			throw new ZhuziException(ErrorCode.MgrUser_Not_Exist);
		}
		MgrUserDetail userDetail = (MgrUserDetail) authentication.getPrincipal();
		logger.info("登录用户userName:{}", userDetail.getUsername());
		return userDetail.getUser();
	}
	

}
